home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolf3dmacsource.sit / Wolf3DMacSource / PlStuff.c < prev    next >
C/C++ Source or Header  |  1994-09-16  |  11KB  |  441 lines

  1. #include "wolfdef.h"
  2.  
  3. /**********************************
  4.  
  5.     Do damage to the player and show the killer
  6.     if you die.
  7.         
  8. **********************************/
  9.  
  10. void TakeDamage(Word points,Word x,Word y)
  11. {
  12.     int angle;
  13.     
  14.     if (gamestate.godmode) {                    /* Don't do anything else if a god */
  15.         return;
  16.     }
  17.         
  18.     if (gamestate.health <= points) {    /* Died? */
  19.         playstate = EX_DIED;        /* Kill off the player */
  20.         gamestate.health = 0;        /* No health */
  21.         killx = x;                    /* Mark the x,y of the killer */
  22.         killy = y;
  23.     } else {
  24.         PlaySound((w_rnd()&1)+SND_OUCH1);            /* Ouch! */
  25.         gamestate.health -= points;    /* Remove the hit points */
  26.     }
  27.  
  28.     IO_DrawHealth(gamestate.health);    /* Draw the health */
  29.  
  30. /* change face to look at attacker */
  31.  
  32.     angle = PointToAngle(x,y) - (gamestate.viewangle<<SHORTTOANGLESHIFT);
  33.     if (angle > 0) {
  34.         if (angle > 0x2000) {
  35.             faceframe = 3;
  36.         } else {
  37.             faceframe = 1;
  38.         }
  39.     } else {
  40.         if (angle < -0x2000) {
  41.             faceframe = 2;
  42.         } else {
  43.             faceframe = 0;
  44.         }
  45.     }
  46.     if (gamestate.health <= 25) {    /* Feel'n pretty bad? */
  47.         faceframe += 5;            /* use beat up frames*/
  48.     }
  49.     IO_DrawFace(faceframe);        /* Draw the face */
  50.     facecount = 120;                /* Hold for 2 seconds */
  51. }
  52.  
  53. /**********************************
  54.  
  55.     Heal the player
  56.         
  57. **********************************/
  58.  
  59. void HealSelf(Word points)
  60. {
  61.     gamestate.health += points;        /* Add in the health */
  62.     if (gamestate.health>100) {
  63.         gamestate.health = 100;    /* Maximum */
  64.     }
  65.     IO_DrawHealth(gamestate.health);    /* Draw the health */
  66.     if (gamestate.health <= 25) {    /* Feel'n good? */
  67.         faceframe = 5;            /* Use beat up frames*/
  68.     } else {
  69.         faceframe = 0;
  70.     }
  71.     IO_DrawFace(faceframe);        /* Redraw the face */
  72. }
  73.  
  74. /**********************************
  75.  
  76.     Award a free life
  77.         
  78. **********************************/
  79.  
  80. void GiveExtraMan(void)
  81. {
  82.     if (gamestate.lives<10) {        /* Too many already? */
  83.         ++gamestate.lives;            /* +1 life */
  84.         IO_DrawLives(gamestate.lives);    /* Redraw the lives */
  85.     }
  86.     PlaySound(SND_EXTRA);                /* Play a sound */
  87. }
  88.  
  89. /**********************************
  90.  
  91.     Award some score to the player and give
  92.     free lives if enough points have been accumulated
  93.         
  94. **********************************/
  95.  
  96. void GivePoints(LongWord points)
  97. {
  98.     gamestate.score += points;    /* Add to the score */
  99.     while (gamestate.score >= gamestate.nextextra) {
  100.         gamestate.nextextra += EXTRAPOINTS;    /* New free man score */
  101.         GiveExtraMan();            /* Give a free man */
  102.     }
  103.     IO_DrawScore(gamestate.score);    /* Draw the new score */
  104. }
  105.  
  106. /**********************************
  107.  
  108.     Award some score to the player and give
  109.     free lives if enough points have been accumulated
  110.         
  111. **********************************/
  112.  
  113. void GiveTreasure(void)
  114. {
  115.     ++gamestate.treasure;        /* Add the value of the treasure */
  116.     while (gamestate.treasure >= 50) {
  117.         gamestate.treasure -= 50;    /* Give a free man for 50 treasures */
  118.         GiveExtraMan();
  119.     }
  120.     IO_DrawTreasure(gamestate.treasure);    /* Draw the treasure amount */
  121. }
  122.  
  123. /**********************************
  124.  
  125.     Award a new weapon, use it if better than what
  126.     the player already has.
  127.         
  128. **********************************/
  129.  
  130. void GiveWeapon(weapontype weapon)
  131. {
  132.     if (gamestate.pendingweapon < weapon) {    /* Better? */
  133.         gamestate.pendingweapon = weapon;    /* Use it! */
  134.     }
  135. }
  136.  
  137. /**********************************
  138.  
  139.     Award some ammo, rearm weapon if knife was the current weapon
  140.         
  141. **********************************/
  142.  
  143. void GiveAmmo(Word ammo)
  144. {
  145.     gamestate.ammo += ammo;        /* Add the ammo */
  146.     if (gamestate.ammo > gamestate.maxammo) {
  147.         gamestate.ammo = gamestate.maxammo;    /* Force maximum */
  148.     }
  149.     switch(gamestate.weapon) {
  150.     case WP_PISTOL:
  151.     case WP_MACHINEGUN:
  152.     case WP_CHAINGUN:
  153.         IO_DrawAmmo(gamestate.ammo);    /* Draw the ammo */
  154.         break;
  155.     case WP_KNIFE:        /* Was it the knife? */
  156.         if (gamestate.ammo == ammo) {    /* Only equip if I had NO ammo */
  157.             gamestate.pendingweapon = WP_PISTOL;
  158.             if (gamestate.machinegun) {
  159.                 gamestate.pendingweapon = WP_MACHINEGUN;
  160.             }
  161.             if (gamestate.chaingun) {        /* Use the best weapon */
  162.                 gamestate.pendingweapon = WP_CHAINGUN;
  163.             }
  164.         }
  165.     }
  166. }
  167.  
  168. /**********************************
  169.  
  170.     Award some gasoline, rearm flamethrower if knife was the current weapon
  171.         
  172. **********************************/
  173.  
  174. void GiveGas(Word ammo)
  175. {
  176.     gamestate.gas += ammo;        /* Add the gasoline */
  177.     if (gamestate.gas > 99) {
  178.         gamestate.gas = 99;        /* Maximum gas */
  179.     }
  180.     if (gamestate.weapon == WP_FLAMETHROWER) {    /* Flamethrower active? */
  181.         IO_DrawAmmo(gamestate.gas);        /* Draw the gas */
  182.     }
  183. }
  184.  
  185. /**********************************
  186.  
  187.     Award some rockets, rearm missile launcher if knife was the current weapon
  188.         
  189. **********************************/
  190.  
  191. void GiveMissile(Word ammo)
  192. {
  193.     gamestate.missiles += ammo;    /* Add in the missiles */
  194.     if (gamestate.missiles > 99) {
  195.         gamestate.missiles = 99;    /* Maximum missiles */
  196.     }
  197.     if (gamestate.weapon == WP_MISSILE) {
  198.         IO_DrawAmmo(gamestate.missiles);    /* Draw the missile count */
  199.     }
  200. }
  201.  
  202. /**********************************
  203.  
  204.     Award a key
  205.         
  206. **********************************/
  207.  
  208. void GiveKey(Word key)
  209. {
  210.     gamestate.keys |= (1<<key);        /* Add in the key mask */
  211.     IO_DrawKeys(gamestate.keys);    /* Draw the keys */
  212. }
  213.  
  214. /**********************************
  215.  
  216.     Play a sound for a bonus item
  217.         
  218. **********************************/
  219.  
  220. void BonusSound(void)
  221. {
  222.     PlaySound(SND_BONUS);
  223. }
  224.  
  225. /**********************************
  226.  
  227.     Play a sound for getting a weapon
  228.         
  229. **********************************/
  230.  
  231. void WeaponSound(void)
  232. {
  233.     PlaySound(SND_GETAMMO|0x8000);
  234. }
  235.  
  236. /**********************************
  237.  
  238.     Play a sound for getting more health
  239.         
  240. **********************************/
  241.  
  242. void HealthSound(void)
  243. {
  244.     PlaySound(SND_HEAL|0x8000);
  245. }
  246.  
  247. /**********************************
  248.  
  249.     Play a sound for getting a key
  250.         
  251. **********************************/
  252.  
  253. void KeySound(void)
  254. {
  255.     PlaySound(SND_GETKEY);
  256. }
  257.  
  258. /**********************************
  259.  
  260.     Picks up the bonus item at mapx,mapy. It is possible to
  261.     have multiple items in a single tile, and they may 
  262.     not all get picked up (maxed out)
  263.         
  264. **********************************/
  265.  
  266. void GetBonus(Word x,Word y)
  267. {
  268.     static_t *StaticPtr;    /* Pointer to static item */
  269.     Word Count;                /* Static count */
  270.     Word touched;            /* Number of items touched */
  271.     Word got;                /* Number of items taken */
  272.     Word Truex,Truey;        /* x,y in pixels */
  273.     
  274.     Count = numstatics;/* Init the count */
  275.     if (!Count) {    /* No items at all? */
  276.         goto EndNow;    /* Leave NOW! */
  277.     }
  278.     touched = 0;        /* No items are marked */
  279.     got = 0;            /* No items found */    
  280.     StaticPtr = statics;    /* Init the main index */
  281.     Truex=x<<FRACBITS;        /* Convert x,y to pixel offsets */
  282.     Truey=y<<FRACBITS;
  283.     do {
  284.         if (((StaticPtr->x&0xff00) != Truex) || ((StaticPtr->y&0xff00) != Truey)) {
  285.             goto NextOne;    /* Not a tile match, skip it */
  286.         }
  287.         ++touched;            /* Found one! */
  288.         ++got;                /* Assume I picked it up */
  289.         
  290.         switch (StaticPtr->pic) {    /* Do the proper action */
  291.         case S_HEALTH:
  292.             if (!gamestate.godmode && gamestate.health == 100) {
  293.                 goto KillGot;        /* No good */
  294.             }
  295.             HealthSound();        /* Add health */
  296.             HealSelf(25);        /* 25 HP's better */
  297.             break;
  298.     
  299.         case S_G_KEY:
  300.         case S_S_KEY:
  301.             GiveKey(StaticPtr->pic - S_G_KEY);    /* Award the key */
  302.             KeySound();                            /* Key sound */
  303.             break;
  304.     
  305.         case S_CROSS:
  306.         case S_CHALICE:
  307.         case S_CHEST:
  308.         case S_CROWN:
  309.             BonusSound();                /* Goodie sound */
  310.             GiveTreasure();                /* Award treasure points */
  311.             ++gamestate.treasurecount;    /* +1 treasure found */
  312.             break;
  313.     
  314.         case S_AMMO:
  315.             if (!gamestate.godmode && gamestate.ammo == gamestate.maxammo) {    /* Ammo full? */
  316.                 goto KillGot;            /* Abort */
  317.             }
  318.             WeaponSound();            /* Tah dah! */
  319.             GiveAmmo(5);            /* 5 bullets */
  320.             break;
  321.     
  322.         case S_MISSILES:
  323.             if (!gamestate.godmode && gamestate.missiles == 99) {    /* Missiles full? */
  324.                 goto KillGot;        /* Abort */
  325.             }
  326.             WeaponSound();            /* Get ammo sound */
  327.             GiveMissile(5);            /* Award 5 missiles */
  328.             break;
  329.     
  330.         case S_GASCAN:
  331.             if (!gamestate.godmode && gamestate.gas == 99) {        /* Gas full? */
  332.                 goto KillGot;        /* Abort */
  333.             }
  334.             WeaponSound();            /* Get ammo sound */
  335.             GiveGas(14);            /* 14 gallons of pure death */
  336.             break;
  337.     
  338.         case S_AMMOCASE:
  339.             if (!gamestate.godmode && gamestate.ammo == gamestate.maxammo) {    /* Ammo full */
  340.                 goto KillGot;        /* Abort */
  341.             }
  342.             WeaponSound();            /* Award the bonus */
  343.             GiveAmmo(25);            /* Give 25 bullets */
  344.             break;
  345.     
  346.         case S_MACHINEGUN:
  347.             if (!gamestate.godmode && gamestate.machinegun && gamestate.ammo == gamestate.maxammo) {
  348.                 goto KillGot;
  349.             }
  350.             GiveAmmo(6);            /* Award bullets */
  351.             if (!gamestate.machinegun) {
  352.                 gamestate.machinegun = TRUE;    /* Make it permanent */
  353.                 GiveWeapon(WP_MACHINEGUN);        /* Arm if better */
  354.             }
  355.             WeaponSound();            /* Got a gun! */
  356.             break;
  357.             
  358.         case S_CHAINGUN:
  359.             GiveAmmo(20);
  360.             if (!gamestate.chaingun) {
  361.                 gamestate.chaingun = TRUE;        /* Make the gun permanent */
  362.                 GiveWeapon(WP_CHAINGUN);    /* Award the chain gun */
  363.             }
  364. IAmSoHappy:
  365.             PlaySound(SND_THUMBSUP);            /* Got a gun! */
  366.             IO_DrawFace(4);            /* Make a happy face! */
  367.             facecount = 120;            /* Hold for 2 seconds */
  368.             break;
  369.     
  370.         case S_FLAMETHROWER:
  371.             if (!gamestate.flamethrower) {
  372.                 gamestate.flamethrower = TRUE;    /* Make flame thrower permanent */
  373.                 GiveWeapon(WP_FLAMETHROWER);    /* Award the flame thrower */
  374.             }
  375.             GiveGas(20);                    /* Start with 20 gallons */
  376.             goto IAmSoHappy;                /* Yeah! */
  377.     
  378.         case S_LAUNCHER:
  379.             if (!gamestate.missile) {
  380.                 gamestate.missile = TRUE;        /* Make missile launcher permanent */
  381.                 GiveWeapon(WP_MISSILE);            /* Award the missile launcher */
  382.             }
  383.             GiveMissile(5);                    /* Start with 5 missiles */
  384.             goto IAmSoHappy;                /* He he he */
  385.     
  386.         case S_ONEUP:
  387.             HealSelf(99);                    /* Fully heal */
  388.             GiveExtraMan();                    /* Give a free man */
  389.             ++gamestate.treasurecount;        /* I got a treasure */    
  390.             break;
  391.     
  392.         case S_FOOD:
  393.             if (!gamestate.godmode && gamestate.health == 100) {    /* Full health? */
  394.                 goto KillGot;            /* Don't get it */
  395.             }
  396.             HealthSound();        /* Feel's good! */
  397.             HealSelf(10);        /* Add 10 points */
  398.             break;
  399.     
  400.         case S_DOG_FOOD:
  401.             if (!gamestate.godmode && gamestate.health == 100) {    /* Full health? */
  402.                 goto KillGot;        /* Abort */
  403.             }
  404.             PlaySound(SND_DOGBARK);    /* Get a bonus */
  405.             HealSelf(4);    /* Not much extra health */
  406.             break;
  407.     
  408.         case S_BANDOLIER:
  409.             if (gamestate.maxammo < 299) {    /* Maximum ammo */
  410.                 gamestate.maxammo += 100;    /* More ammo! */
  411.             }
  412.             WeaponSound();    /* Get a bonus */
  413.             GiveAmmo(20);    /* Award ammo */
  414.             GiveGas(2);
  415.             GiveMissile(5);
  416.             break;    
  417.                     
  418.         default:
  419.             touched--;        /* Huh? */
  420.             goto KillGot;    /* Can happen if a bonus item is dropped on a scenery pic */
  421.         }
  422.     /* remove the static object */
  423.     
  424.         --numstatics;        /* One less item */
  425.         StaticPtr[0] = statics[numstatics];    /* Copy the last item */
  426.         goto SkipInc;        /* Process this entry again! */
  427. KillGot:
  428.         --got;                    /* Invalidate the touch */
  429. NextOne:
  430.         ++StaticPtr;            /* Next pointer */
  431. SkipInc:;
  432.     } while (--Count);
  433.  
  434.     if (touched == got) {    /* All items taken? */
  435. EndNow:                        
  436.         tilemap[y][x] &= ~TI_GETABLE;        /* No more getable items */
  437.     }
  438. }
  439.  
  440.  
  441.